<template>
  <div class="app-container">
    <div v-if="user">
      <el-row :gutter="20">

        <el-col :span="6" :xs="24">
          <user-card :user="user" />
        </el-col>

        <el-col :span="18" :xs="24">
          <el-card>
            <el-tabs v-model="activeTab">
              <el-tab-pane label="修改密码" name="activity">
                <activity :user="user" />
              </el-tab-pane>
              <el-tab-pane label="忘记密码" name="timeline">
                <timeline :user="user" />
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>

      </el-row>
    </div>
  </div>
</template>

<script>
import UserCard from './components/UserCard'
import Activity from './components/Activity'
import Timeline from './components/Timeline'

import { getProfile } from '@/api/user'

export default {
  name: 'Profile',
  components: { UserCard, Activity, Timeline },
  data() {
    return {
      user: {
        name: '',
        roles: '',
        mobile: '',
        avatar: '',
        introduction: ''
      },
      activeTab: 'activity'
    }
  },
  created() {
    console.log('初始化用户信息:::')
    this.initUsrMsg()
  },
  methods: {
    initUsrMsg() {
      console.log('开始执行:::')
      getProfile().then(res => {
        console.log('调取接口=>', res)
        this.user = {
          name: res.data.name,
          roles: res.data.roles.join('|'),
          mobile: res.data.mobile,
          avatar: res.data.avatar,
          introduction: res.data.introduction
        }
      })
    }
  }
}
</script>
